function show(){
  // 返回一个promise对象
  return new Promise((resolve, reject) => {
    axios({
      url: '/index/skyrocketVideo',
      method: 'get',
    })
    .then((res) => { 
      resolve(res.data.data.data);
    })
    .catch(function (error) {
      reject(error);
    });
  });
}
async function hello(){
  let a=await show();
  var trl=document.getElementsByClassName('trl-ul')[2];
  for(var i=0;i<5;i++){
    trl.innerHTML+=`
      <li class="trl-item">
          <a class="rank-list" href='/play?${a[i].videoId}'>
              <div class='rank-num'><span class='rank-num-span'>${i+1}</span></div>
              <div class="rank-content">
                  <span class='rush'>${a[i].videoName}</span>
                  <p style="color:hsla(0,0%,100%,.4);overflow: hidden;white-space:nowrap;text-overflow: ellipsis;font-size: 13px;">${a[i].introduction}</p>
              </div>
          </a>
      </li>

    `
  }

  var rank=document.getElementsByClassName('rank-num-span');
  rank[16].style.color='#ff473a'
  rank[17].style.color='#f73'
  rank[18                                                                                                                                                                                                                                                                                                                                                                                       ].style.color='#ffa82e'
}
hello();

var userIdmessage =  document.getElementById("userIdmessage")
var useId=userIdmessage.innerHTML
// 反馈的弹窗
var submit = document.getElementsByClassName('submit')[0];
var feedbacks=document.getElementsByClassName('feedbacks')[0];
var couple=document.getElementsByClassName('couple')[0];
submit.onclick=function(){
    if(feedbacks.value==''||couple.value==''){
      alert('请把反馈信息填写完整')
    }else{
      alert('反馈成功')
      feedbacks.value='';
      couple.value='';
    }
}
// 开始交互
// 鼠标放上去会改变内容
var mod1 = document.getElementsByClassName('qy-mod-div')
var mod2 = document.getElementsByClassName('hovers')
var qy_mod_li=document.getElementsByClassName('qy-mod-li')
for(let i=0,len=qy_mod_li.length;i<len;i++){
    qy_mod_li[i].addEventListener('mouseover',function(){
        mod1[i].style.display='none';
        mod2[i].style.display='block';
    })
    qy_mod_li[i].addEventListener('mouseout',function(){
        mod1[i].style.display='block';
        mod2[i].style.display='none';
    })
}
// 鼠标放上去会出现几张照片
var manyImg=document.getElementsByClassName('manyImg')
var kind=document.getElementsByClassName('video-kind')
for(let i=0,len=manyImg.length;i<len;i++){
  kind[i].addEventListener('mouseover',function(){
    manyImg[i].style.display='block';
  })
  kind[i].addEventListener('mouseout',function(){
      manyImg[i].style.display='none';
  })
}
// 1.主页轮播图
var slider = document.getElementById("slider"); 
var arrUrl=[];
var nice =''
function showImg(){
  axios({
    url: '/photo',
    method: 'get',
  })
  .then(function(data){
      nice=`
      <a href="javascript:;" class='aImg'>                                        
        <img src='${data.data.data[0].videoPhoto}' id='img'>                        
      </a>
    `
    slider.innerHTML=nice;
    for(var i=0;i<data.data.data.length;i++){
        var dotUl=document.getElementsByClassName('dotul')[0]
        dotUl.innerHTML+=`
          <li class="dotli"><a class='dota'>${data.data.data[i].videoName}<p class='dotp'>${data.data.data[i].videoBriefly}</p></a></li>                                                         
        `
        arrUrl.push(data.data.data[i].videoPhoto);
    } 
     //首先要获取元素
     var dots = document.getElementsByClassName('dotli');
     var left = document.getElementById("left"); 
     var right = document.getElementById("right");
     var img=document.getElementById('img');
     var num = 0; 
     //图片位置 
     left.onclick = function(ev){ 
         num--; 
         if (num == -1){
             num = dots.length-1;//如果到了第一张，返回最后一张 
         } 
         changeImg(); 
     };
     right.onclick = function (ev) { 
         num++; 
         if (num == dots.length){ 
             num = 0;//如果是最后一张，则返回第一张 
         } 
         changeImg(); 
     };
  
   //点击小圆点跳转到对应的图片 
     for (var i=0;i<dots.length;i++){ 
            dots[i].index = i; 
            dots[i].onclick = function (ev) {
                num = this.index; 
                changeImg(); 
            } 
     }
    //  //图片切换函数 
    function changeImg() { 
      img.src=arrUrl[num]
      for (var i = 0;i<dots.length;i++){//改变原点样式 
          dots[i].className = "dotli";
      } 
      dots[num].className = "dotli active"; 
    }
    changeImg(); 
  })
  .catch(function(err){
    console.log('失败')
  })
      
}
showImg()


    // 懒加载
  //  var main=document.getElementsByClassName('layout')[3];
  //  var skin=document.getElementsByClassName('ph-skin-wrap')[0]
  //  var lay=document.getElementsByClassName('layout')[4]
  // function lazy(){
  //     // const box = document.querySelector('.box')
  //     const io=new IntersectionObserver(observeCall)
  //     function observeCall(config){
  //       if(config[0].intersectionRatio>0){
  //           // 当你规定的div出来的时候，取消对他的监听
  //           io.unobserve(main.children[layout-right].lastChild)
  //           console.log(135)
  //           console.log(main.children[layout-right].lastChild)
  //           skin.push(...lay)

  //       }
  //     }
  //     io.observe(main.children[layout-right].lastChild)
  // }
  // lazy()
    
    // var num = 1;
    // $("#ShowPanal").scroll(function () {
    //     var h = $(this).height();//div可视区域的高度
    //     var sh = $(this)[0].scrollHeight;//滚动的高度，$(this)指代jQuery对象，而$(this)[0]指代的是dom节点
    //     var st = $(this)[0].scrollTop;//滚动条的高度，即滚动条的当前位置到div顶部的距离
    //     //上面的代码是判断滚动条滑到底部的代码
    //     if (h + st >= sh) {
    //         //暂停滚动
    //         $(this)[0].disabled = false;
    //         num = num + 7;
    //         $("#dataPanal").append("新内容");
    //         //启用滚动
    //         $(this)[0].disabled = true;
    //     }
    // })


// 会员的左右切换
// const cl = name=>{
//     return document.getElementsByClassName(name);
// }

var slides = document.getElementsByClassName("fade");
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
  showSlides(slideIndex += n);
} 
function currentSlide(n) {
  showSlides(slideIndex = n);
} 
function showSlides(n) {
  if (n > slides.length) {slideIndex = 1} 
  if (n < 1) {slideIndex = slides.length}
  for (var i = 0; i < slides.length; i++) {
      slides[i].style.display = "none"; 
  }
slides[slideIndex-1].style.display = "block"; 
}

// 点击反馈会出现弹框
var feed=document.getElementsByClassName('feedback')[0];
var hideBack=document.getElementsByClassName('hideBack')[0];
var hideBackForm=document.getElementsByClassName('hideBackForm')[0];
var closeBack=document.getElementsByClassName('closeBack')[0];
var submit = document.getElementsByClassName('submit')[0];
closeBack.onclick = closeFeedback;
feed.onclick=function(){
    hideBack.style.display='block';
    hideBackForm.style.opacity='1';
}
function closeFeedback(){
    hideBack.style.display='none';
    hideBackForm.style.opacity='0';
}

//返回顶部的按钮
var totop=document.getElementsByClassName("totop")[0];
var feedback=document.getElementsByClassName('feedback')[0]
var header=document.getElementsByClassName('header-wrap')[0];
document.onscroll=function(){
	var top=document.documentElement.scrollTop;
	if(top>1000){
		totop.style.display="block";
        feedback.style.display="block";
        header.style.display="block";
	}else {
        totop.style.display="none";
		feedback.style.display="none";
	}
}
function turntop(){
	var backTopTimer=setInterval(function(){
		var topH=document.documentElement.scrollTop||document.body.scrollTop;
		var backTopSpeed=Math.floor(-topH/8);
		if(topH>0){
			document.documentElement.scrollTop=document.body.scrollTop=topH+backTopSpeed;	
		}else {
			clearInterval(backTopTimer);
			
		}
	},10);
}


// 电视剧的左右切换
var slides1 = document.getElementsByClassName("fade1");
var slideIndex1 = 1;
showSlides1(slideIndex1);
function pluSlides(n) {
  showSlides1(slideIndex1 += n);
} 
function currentSlide1(n) {
  showSlides1(slideIndex1 = n);
} 
function showSlides1(n) {
  if (n > slides1.length) {slideIndex1 = 1} 
  if (n < 1) {slideIndex1 = slides1.length}
  for (var i = 0; i < slides1.length; i++) {
      slides1[i].style.display = "none"; 
  }
slides1[slideIndex1-1].style.display = "block"; 
}


// 电影的切换
var slides2 = document.getElementsByClassName("fade2");
var slideIndex2 = 1;
showSlides1(slideIndex2);
function plSlides(n) {
  showSlides2(slideIndex1 += n);
} 
function currentSlide2(n) {
  showSlides2(slideIndex2 = n);
} 
function showSlides2(n) {
  if (n > slides2.length) {slideIndex2 = 1} 
  if (n < 1) {slideIndex2 = slides2.length}
  for (var i = 0; i < slides2.length; i++) {
      slides2[i].style.display = "none"; 
  }
slides2[slideIndex2-1].style.display = "block"; 
}

// 综艺的切换
var slides3 = document.getElementsByClassName("fade3");
var slideIndex3 = 1;
showSlides3(slideIndex3);
function pSlides(n) {
  showSlides3(slideIndex1 += n);
} 
function currentSlide2(n) {
  showSlides3(slideIndex3 = n);
} 
function showSlides3(n) {
  if (n > slides3.length) {slideIndex3 = 1} 
  if (n < 1) {slideIndex3 = slides3.length}
  for (var i = 0; i < slides3.length; i++) {
      slides3[i].style.display = "none"; 
  }
  slides3[slideIndex3-1].style.display = "block"; 
}

var rank=document.getElementsByClassName('rank-num-span');
console.log(rank.length)
console.log(rank[11])
console.log(rank[12])
console.log(rank[15])
rank[0].style.color='#ff473a'
rank[1].style.color='#f73'
rank[2].style.color='#ffa82e'
rank[8].style.color='#ff473a'
rank[9].style.color='#f73'
rank[10].style.color='#ffa82e'
